﻿using System;
using NUnit.Framework;

namespace PropertyExpression.TypedSqlBuilder.Test
{
    [TestFixture]
    public class SqlTest2
    {
        [Test]
        public void Test4()
        {
            var query = NewMethod1(DateTime.Now, DateTime.Now);
            Console.WriteLine(query);
        }

        private static IInnerJoin<SalesOrderHeaderProjection> NewMethod1(
            DateTime startOrderDate, DateTime endOrderDate)
        {
            return
                from salesOrderHeader in Schema.SalesOrderHeaders
                from salesOrderDetail in Schema.SalesOrderDetails.InnerJoin(salesOrderDetail =>
                    salesOrderDetail.SalesOrderID().Equal(salesOrderHeader.SalesOrderID()))
                from specialOfferProduct in Schema.SpecialOfferProducts.InnerJoin(specialOfferProduct =>
                    salesOrderDetail.SpecialOfferID().Equal(specialOfferProduct.SpecialOfferID())
                        .And(salesOrderDetail.ProductID().Equal(specialOfferProduct.ProductID())))
                select
                    salesOrderHeader.OrderDate().Between(startOrderDate.Const(), endOrderDate.Const()).Where().To(
                    Query.Select<SalesOrderHeaderProjection>()
                        .OrderDate(salesOrderHeader.OrderDate())
                );
        }
    }
}
